<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>Signin Template for Bootstrap</title>
    <!-- Bootstrap core CSS -->
    <link href="asserts/css/bootstrap.min.css" rel="stylesheet">
    <!-- Custom styles for this template -->
    <link href="asserts/css/signin.css" rel="stylesheet">
    <script type="text/javascript" src="asserts/js/jquery-3.2.1.slim.min.js"></script>
    <script src="webjars/jquery/3.4.1/jquery.min.js"></script>

</head>

<body class="text-center">
<form class="form-signin" >
    <img class="mb-4" src="asserts/img/bootstrap-solid.svg" alt="" width="72" height="72">

    <h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>

    <!--登录错误显示-->
    <!--<p style="color: red" th:text="${msg}" th:if="${not #strings.isEmpty(msg)}"></p>-->
    <label class="sr-only">Schoolname</label>
    <input type="text" class="form-control" placeholder="Schoolname" name="schoolname" required=""
           autofocus="" id="schoolname">
    <label class="sr-only">Username</label>
    <input type="text" class="form-control" placeholder="Username" name="username" required=""
           autofocus="" id="username">
    <label class="sr-only">Password</label>
    <input type="password" class="form-control" name="password" placeholder="Password" id="password1"
           required="">
    <label class="sr-only">Confirm password</label>
    <input type="password" class="form-control" name="password2" placeholder="Password" id="password2"
           required="">
    <div class="checkbox mb-3">
        <label>
        </label>
    </div>
    <button class="btn btn-lg btn-primary btn-block" type="button" id="signBtn">Register
        in
    </button>
    <p class="mt-5 mb-3 text-muted">© 2017-2018</p>

</form>



<script>
    $(document).ready(function () {
        $("#signBtn").click(function () {
            if ($("#password1").val() == $("#password2").val()) {
                var params = {
                    "schoolname": $("#schoolname").val(),
                    "username": $("#username").val(),
                    "password": $("#password1").val()
                };
                console.log(params)
                // var data = JSON.stringify(params);
                if (params.username == null || params.password == null || params.schoolname == null) {
                    alert("学校名称、账号和密码不能为空");
                } else {
                    $.ajax({
                        type: "POST",
                        dataType: "json",//返回的数据类型
                        // contentType : "application/json",//上传内容格式为json结构
                        // traditional: true, //traditional 为true阻止深度序列化
                        url: "/postgraduate/user/register",
                        data: params,
                        success: function (res) {
                            if (res.code == 200) {
                                location.href = "login.html"
                            } else {
                                alert(res.msg);
                                return;
                            }
                        },
                        error: function (err) {
                            alert("服务器内部错误");
                        }
                    })
                }
            } else {
                alert("密码不一致")
                return false;
            }

        })
    })

</script>
</body>

</html>